<template>
	<div>
		<input type="button" id="btnSend" value="发送消息" />
		<input type="button" id="btnClose" value="关闭连接" />
	</div>
</template>

<script>
	export default {
data(){
	return{
		socket:null
	}
},
	
	methods:{
		aaaa(){
		if (typeof (WebSocket) == "undefined") {
		console.log("您的浏览器不支持WebSocket");
		} else {
		console.log("您的浏览器支持WebSocket");
		this.socket = new WebSocket("ws://192.168.0.108:8088/websocket/admin");

		this.socket.onopen = function() {
			console.log("Socket已打开");
		};

		this.socket.onmessage = function(ev) {
			console.log(ev.data);
		};

		this.socket.onclose = function() {
			console.log("Socket已关闭");
		};
		this.socket.onerror = function() {
			alert("Socket发生了错误")
		};
		window.onunload = function() {
  			this.socket.close();
 		};
	
	}
	}
	},
	mounted(){
		this.aaaa()
	},
	// $(function() {
	// 	$("#btnSend").click(function() {
	// 		this.socket.send("这是来自客户端的消息：" + location.href);
	// 	});
	// 	$("#btnClose").click(function() {
	// 		this.socket.close();
	// 	});
	// });
}
</script>

<style>
</style>